﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Negocios;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {

        public static bool inserir;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

       
        protected void btSalva_Click(object sender, EventArgs e)
        {
            
            PacoteBoMetodos pbom = new PacoteBoMetodos();
            PacoteBO pbo = new PacoteBO();
            pbo.Nome = tbNome.Text;
            pbo.Valor = (float)Convert.ToDouble(tbValor.Text);
            pbo.Data = Convert.ToDateTime(tbData.Text);


            if (inserir)
            {
               pbom.Inserir(pbo);
            }
            else
            {
                pbo.Id = Convert.ToInt32(tbID.Text);
                pbom.Alterar(pbo);
            }
            gvPacote.DataBind();

            Limpar();

        }


        protected void Limpar()
        {
            tbNome.Text = "";
            tbValor.Text = "";
            tbData.Text = "";
        
        }

        protected void btCancela_Click(object sender, EventArgs e)
        {
            Limpar();
        }

        protected void btIncluirCanal_Click(object sender, EventArgs e)
        {


            //ddCanal.SelectedValue();
            //Inserir = false;
            LinkButton lb = (LinkButton)sender;
            DataControlFieldCell celula = (DataControlFieldCell)lb.Parent;
            GridViewRow linha = (GridViewRow)celula.Parent;
            int ID = Convert.ToInt32(linha.Cells[0].Text);
            CanalBOMetodos cBOM = new CanalBOMetodos();
            CanalBO cBO = cBOM.Consultar(ID);
                        
        }

        protected void btCadastrar_Click(object sender, EventArgs e)
        {
            inserir = true;
            tbNome.Focus();
            tbNome.Text = "";
            tbNome.Enabled = true;
            tbValor.Text = "";
            tbValor.Enabled = true;
            tbData.Text = "";
            tbData.Enabled = true;
        }

        protected void lbAtualizar_Click(object sender, EventArgs e)
        {
            inserir = false;
            LinkButton lb = (LinkButton)sender;
            DataControlFieldCell celula = (DataControlFieldCell)lb.Parent;
            GridViewRow linha = (GridViewRow)celula.Parent;
            int ID = Convert.ToInt32(linha.Cells[0].Text);
            PacoteBoMetodos pBOM = new PacoteBoMetodos();
            
            PacoteBO pBO = pBOM.Consultar(ID);

            tbID.Text = pBO.Id.ToString();
            tbNome.Text = pBO.Nome;
            tbData.Text = pBO.Data.ToShortDateString();
            tbValor.Text = pBO.Valor.ToString();            
        }

        protected void btPesquisar_Click(object sender, EventArgs e)
        {
            
        }

        protected void lbRemover_Click(object sender, EventArgs e)
        {

            LinkButton lb = (LinkButton)sender;
            DataControlFieldCell celula = (DataControlFieldCell)lb.Parent;
            GridViewRow linha = (GridViewRow)celula.Parent;
            int ID = Convert.ToInt32(linha.Cells[0].Text);
            PacoteBoMetodos pBOM = new PacoteBoMetodos();
                        
            pBOM.Excluir(ID);

            gvPacote.DataBind();

        }

      }
}
